<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let input = `5
        5000 2000 5000 8000 1800`
        let N = parseInt(input.split('\n')[0].trim(), 10)
        let nums = input.split('\n')[1].trim().split(' ').map((v) => { return parseInt(v) })

        let tree = Array.from(nums, () => { return [0, null, null, null, null] })
        let max = 1;
        tree[0][0] = nums[0]
        for (let i = 1; i < N; i++) {
            if (nums[i] < tree[i - 1][0] - 500) {
                tree[i]=nums[i];
                tree[i]
            }
        }



        console.log(tree);





        console.log(N, nums);

    </script>
</body>

</html>